package com.sky.common.task;

import com.sky.business.sys.domain.CameraConfig;
import com.sky.business.sys.domain.SystemConfig;
import com.sky.business.sys.service.CameraConfigService;
import com.sky.business.sys.service.ReportMessageService;
import com.sky.business.sys.service.SystemConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 上报设备信息定时任务
 */
@Slf4j
@Component
public class ReportDeviceInfoTask {

    @Autowired
    private CameraConfigService cameraConfigService;

    @Autowired
    private SystemConfigService systemConfigService;

    @Autowired
    private ReportMessageService reportMessageService;

    @Scheduled(cron = "0 25 * * * ?")
    public void doTask() {
        SystemConfig systemConfig = systemConfigService.getSystemConfig();
        List<CameraConfig> cameraConfigList = cameraConfigService.list();
        for(CameraConfig cameraConfig:cameraConfigList){
            try {
                reportMessageService.reportDeviceInfo(cameraConfig,systemConfig);
            } catch (Exception e) {
                log.error("上报设备信息发生异常",e);
            }
        }
    }
}
